package org.sy.lab.多线程基础._4_执行器._2_Future线程控制._2_处理第一个结果;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

import org.sy.lab.多线程基础._4_执行器._2_Future线程控制._3_处理所有结果.MyCallable;

//invokeAny 返回第一个完成没有抛异常的任务结果
public class Main {

	public static void main(String[] args) {
		
		ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(2);
		
		MyCallable myCallable = new MyCallable(5, "任务1");
		MyCallable myCallable2 = new MyCallable(2, "任务2");
		
		List<MyCallable> list =new ArrayList<MyCallable>();
		list.add(myCallable);
		list.add(myCallable2);
		
		try {
			System.out.println(executor.invokeAny(list));
		} catch (InterruptedException | ExecutionException e) {
			e.printStackTrace();
		}
		executor.shutdown();
	}
}
